package player.ui;

import java.io.File;
import java.util.Observable;
import java.util.Observer;

import javax.swing.table.DefaultTableModel;

import player.MusicPlayer;
/**
 * Observer to observe the playlist in the player, and update the table.
 */
public class PlaylistObserver implements Observer {

	MusicPlayer player;
	DefaultTableModel model;
	int musicID = 1;
	
	/**
	 * Create this playlist observer.
	 * @param player is the music player the this observer observes.
	 * @param model is the table model to be modify.
	 */
	public PlaylistObserver(MusicPlayer player, DefaultTableModel model){
		this.player = player;
		this.model = model;
		player.addObserver(this);
	}
	
	@Override
	public void update(Observable o, Object file) {
		if( file != null ){
			File file_temp = (File) file;
			if( file_temp.getName().contains(".mp3"))
				model.addRow( new Object[]{ player.getTrackID(), file_temp.getName()});
		}
	}

}
